﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GenericValidation;
using System.Reflection;
using GenericValidation.Sample.Validation;
using Microsoft.Practices.Unity;
using System.Configuration;
using GenericValidation.Sample.Model;

namespace GenericValidation.Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            var user = new User()
            {
                IsEnabled = true,
                Age = 23,
                UserName = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
            };

            var employee = new Employee()
            {
                IsEnabled = true,
                UserName = "bbbbbbbbbbbbbbbbbbbbbbbbbasdasdasdasdasdasdasdasdasdasdasdasdbbbbbbbbbbbbbbbbbbbbb",
                Age = 456,
                Salary = 123,
            };

            var container = new UnityContainer();
            Configure(container);

            var validation = container.Resolve<IValidationManager>();

            var result = validation.Validate(employee, ValidationSettings.InsertTag, ValidationSettings.AlwaysTag);
            result.ErrorInfo.ToList().ForEach(p => Console.WriteLine(p));

            Console.ReadLine();
        }

        static void Configure(IUnityContainer container)
        {
            container.RegisterType<IValidationManager, ValidationManager>()
                .RegisterType<IValidationFactory, UnityValidationFactory>(new InjectionConstructor(container, Assembly.GetExecutingAssembly()));
        }
    }
}
